﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; 
using NTTDATA.BEENChina.ResultCertification.Config;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil;
using NTTDATA.BEENChina.ResultCertification.PropertyGridUtil.CustomObject;
using NTTDATA.BEENChina.ResultCertification.Split;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0401", Name = "特定部分等于(包含)XXX", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0401 : VerfityOneResult
    {

        [Category("要检查的部分"), Description("指定要检查的部分")]
        public EnumSpeicficEntryPart SpeicficPart 
        {
            get { return this._speicficPart; }
            set { this._speicficPart = value; }
        } 

        private EnumSpeicficEntryPart _speicficPart = EnumSpeicficEntryPart.All;

        private CustomCollection<SpecialStringArray> _datalist = new CustomCollection<SpecialStringArray>() { Description = "指定数据列表" };


        [Category("指定数据列表"), Description("输入指定数据项目")]
        [TypeConverter(typeof(CustomCollectionConverter<SpecialStringArray>))]
        [RefreshProperties(RefreshProperties.All)]
        public CustomCollection<SpecialStringArray> DataList
        {
            get { return _datalist; } 
        }
        
  
        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;
            if (entryCommon.Equals("30"))
            {
                return false;
            }

            if (result == null)
            {
                return false;
            }
             

            //也可以按组查询 指定行列为特定值 
            bresult = DataList.Where(t => !Enum.GetName(typeof(EnumSpecialType), t.SpecialType).Contains("Un"))
                                .Select(t => t.Group).Distinct()
                                .Any(g => DataList.Where(t => t.Group.Equals(g))
                                .All(o => CheckSpecificCharacter(result, GetSpeicficResult, o)));

            if (!bresult)
            {
                bresult = DataList.Where(t => Enum.GetName(typeof(EnumSpecialType), t.SpecialType).Contains("Un"))
                                .Select(t => t.Group).Distinct()
                                .Any(g => DataList.Where(t => t.Group.Equals(g))
                                .Any(o => CheckSpecificCharacter(result, GetSpeicficResult, o)));
            }
            if (bresult)
            {
                System.Console.WriteLine("VerfityN0401");
            }

            return bresult;
        }

      
        
        private string GetSpeicficResult(string colResult)
        {
            switch (this.SpeicficPart)
            { 
                case EnumSpeicficEntryPart.All:
                    return colResult.Replace("/", string.Empty);
                case EnumSpeicficEntryPart.DateTime:
                    return new SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult).GetDate().Replace("/", string.Empty);
                case EnumSpeicficEntryPart.Text:
                    return new SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult).GetText();
                default :
                    return "";
            }
        }

       
    }
}
